package cn.stylefeng.guns.modular.shi.controller;

import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.shi.entity.SRecommendEvaluation;
import cn.stylefeng.guns.modular.shi.model.params.SRecommendEvaluationParam;
import cn.stylefeng.guns.modular.shi.service.SRecommendEvaluationService;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.core.reqres.response.ResponseData;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.List;


/**
 * 控制器
 * 种草评价表
 * @author 石博士
 * @Date 2019-11-15 11:10:10
 */
@Controller
@RequestMapping("/sRecommendEvaluation")
public class SRecommendEvaluationController extends BaseController {

    private String PREFIX = "/sRecommendEvaluation";

    @Autowired
    private SRecommendEvaluationService sRecommendEvaluationService;


    /**
     * 跳转到主页面
     */
    @RequestMapping("")
    public String index(String nameId , HttpSession session) {
        session.setAttribute("nameId",nameId);
        return PREFIX + "/sRecommendEvaluation.html";
    }


    /**
     * 新增页面
     */
    @RequestMapping("/add")
    public String add() {
        return PREFIX + "/sRecommendEvaluation_add.html";
    }


    /**
     * 编辑页面
     */
    @RequestMapping("/edit")
    public String edit() {
        return PREFIX + "/sRecommendEvaluation_edit.html";
    }


    /**
     * 新增接口
     */
    @RequestMapping("/addItem")
    @ResponseBody
    public ResponseData addItem(SRecommendEvaluationParam sRecommendEvaluationParam) {
        this.sRecommendEvaluationService.add(sRecommendEvaluationParam);
        return ResponseData.success();
    }


    /**
     * 编辑接口
     */
    @RequestMapping("/editItem")
    @ResponseBody
    public ResponseData editItem(SRecommendEvaluationParam sRecommendEvaluationParam) {
        this.sRecommendEvaluationService.update(sRecommendEvaluationParam);
        return ResponseData.success();
    }


    /**
     * 删除接口
     */
    @RequestMapping("/delete")
    @ResponseBody
    public ResponseData delete(SRecommendEvaluationParam sRecommendEvaluationParam) {
        this.sRecommendEvaluationService.delete(sRecommendEvaluationParam);
        return ResponseData.success();
    }


    /**
     * 查看详情接口
     */
    @RequestMapping("/detail")
    @ResponseBody
    public ResponseData detail(SRecommendEvaluationParam sRecommendEvaluationParam) {
        SRecommendEvaluation detail = this.sRecommendEvaluationService.getById(sRecommendEvaluationParam.getId());
        return ResponseData.success(detail);
    }


    /**
     * 根据商品的id查询列表 根据时间排序
     */
    @ResponseBody
    @RequestMapping("/list")
    public LayuiPageInfo list(SRecommendEvaluationParam sRecommendEvaluationParam, HttpSession session) {
        LayuiPageInfo pageBySpec = this.sRecommendEvaluationService.findPageBySpec(sRecommendEvaluationParam);
        QueryWrapper<SRecommendEvaluation> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("name_id",session.getAttribute("nameId"));
        queryWrapper.orderByDesc("evaluation_time");
        List<SRecommendEvaluation> list = sRecommendEvaluationService.list(queryWrapper);
        pageBySpec.setData(list);
        return pageBySpec;
    }









}


